package com.agriculture.repository;

import com.agriculture.entity.GeoDevice;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface GeoDeviceRepository extends JpaRepository<GeoDevice, Integer> {
    
    List<GeoDevice> findByStatus(GeoDevice.DeviceStatus status);
    
    @Query(value = "SELECT d FROM GeoDevice d WHERE within(d.currentPosition, :polygon) = true")
    List<GeoDevice> findDevicesWithinPolygon(@Param("polygon") org.locationtech.jts.geom.Polygon polygon);
}